package xyz.bali16.module.activeuser.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gitee.starblues.bootstrap.annotation.AutowiredType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xyz.bali16.application.service.UserService;
import xyz.bali16.module.activeuser.entity.Statistics;
import xyz.bali16.module.activeuser.mapper.StatisticsMapper;

/**
 * @author bali2 on 9/3/2023.
 * @version 1.0
 */
@Service
public class StatisticsServiceImpl extends ServiceImpl<StatisticsMapper, Statistics> implements StatisticsService {


    @Autowired
    @AutowiredType(AutowiredType.Type.MAIN_PLUGIN)
    UserService userService;

    @Autowired
    ArticleServiceCaller articleServiceCaller;
    @Autowired

    CommentServiceCaller commentServiceCaller;

    @Override
    public Statistics indexData()  {

        String today = cn.hutool.core.date.DateUtil.date().toString("yyyy-MM-dd");
        String yesterday = cn.hutool.core.date.DateUtil.yesterday().toString("yyyy-MM-dd");
        Integer postCount =articleServiceCaller.countArticle();
        Statistics statistics = new Statistics();
        statistics.setTotalPost(postCount);
        statistics.setNewUserNum(userService.getRegisterNumByDate(today));
        statistics.setYesterdayNewUserNum(userService.getRegisterNumByDate(yesterday));
        statistics.setTotalUser(userService.count());
        statistics.setYesterdayCommentCount(commentServiceCaller.getYesterdayCount());
        statistics.setCommentCount(commentServiceCaller.countComment());
        return statistics;
    }



}

